<?php

namespace app\common\model;

use think\exception\DbException;
use think\Model;
use think\Paginator;

/**
 * 申论管理
 */
class Explaining extends Model
{
    protected $name = 'explaining';


    /**
     * 申论列表
     * @param mixed $where 
     * @return Paginator 
     * @throws DbException 
     */
    public function getList($where)
    {
        $list = self::alias('a')
            ->join('user b', 'a.user_id = b.id') # 查询学生信息
            ->where(function ($query) use ($where) {
                # 用户端登录
                if (isset($where['user_id']) && $where['user_id'] > 0) {
                    $query->where('a.user_id', $where['user_id']);
                }
                # 教师端登录
                if (isset($where['teacher_id']) && $where['teacher_id'] > 0) {
                    $query->where('a.teacher_id', $where['teacher_id']);
                }
                if (isset($where['status']) && $where['status'] > 0) {
                    $query->where('a.status', $where['status']);
                }
            })
            ->field('a.id as explaining_id,a.type,a.title,a.content,a.status,a.createtime,b.nickname as user_name,b.avatar as user_avatar')
            ->order('createtime', 'desc')
            ->paginate();
        return $list;
    }
}
